package com.itbuka.vip.controller;

import com.itbuka.vip.domain.VipEvaluate;
import com.itbuka.vip.service.VipEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.itbuka.entity.Result;
import com.itbuka.entity.PageResult;
import com.github.pagehelper.Page;

import java.util.List;

/**
 * 会员评价
 */
@RestController
@RequestMapping("/VipEvaluate")
public class VipEvaluateController {

    @Autowired
    private VipEvaluateService vipEvaluateService;

    /**
     * 查询全部
     */
    @GetMapping("/selectAll")
    public Result<List<VipEvaluate>> selectAll() {
        return Result.ok("查询成功", vipEvaluateService.selectAll());
    }

    /**
     * 条件查询
     */
    @PostMapping("/selectList")
    public Result<List<VipEvaluate>> select(@RequestBody VipEvaluate vipEvaluate) {
        return Result.ok("条件查询成功", vipEvaluateService.selectList(vipEvaluate));
    }

    /**
     * 新增
     */
    @PostMapping("/insert")
    public Result<?> insert(@RequestBody VipEvaluate vipEvaluate) {
        vipEvaluateService.insert(vipEvaluate);
        return Result.ok("新增成功");
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    public Result<?> delete(@RequestParam String ids) {
        vipEvaluateService.delete(ids);
        return Result.ok("删除成功");
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result<?> update(@RequestBody VipEvaluate vipEvaluate) {
        vipEvaluateService.update(vipEvaluate);
        return Result.ok("修改成功");
    }

    /**
     * 分页搜索实现
     */
    @GetMapping(value = "/pageAll")
    public Result<?> pageAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page<VipEvaluate> pageList = vipEvaluateService.pageAll(page, size);
        PageResult<?> pageResult = new PageResult<>(pageList.getTotal(), pageList.getResult());
        return Result.ok("查询成功", pageResult);
    }

    /**
     * 分页条件搜索实现
     */
    @GetMapping(value = "/pageList")
    public Result<?> pageList(@RequestBody VipEvaluate vipEvaluate, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page<VipEvaluate> pageList = vipEvaluateService.pageList(vipEvaluate, page, size);
        PageResult<?> pageResult = new PageResult<>(pageList.getTotal(), pageList.getResult());
        return Result.ok("查询成功", pageResult);
    }

    /**
     * 会员评价启用、停用
     */
    @GetMapping("/status")
    public Result<?> status(@RequestParam Long id, @RequestParam Integer status) {
        Integer integer = vipEvaluateService.status(id, status);
        if (integer == -1) {
            return Result.fail("该会员评价id没有数据");
        }
        if (integer == -2) {
            return Result.fail("会员评价状态修改失败");
        }
        return Result.ok("会员评价状态修改成功");
    }
}




